package com.woniuxueyuan.util;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest {
    public static void main(String[] args) {
        List<String> list = Arrays.asList("1", "2", "3", "4", "5", "6","1");
        //用stream对集合操作

        //1:用创建操作流化集合
        //对集合流化
        Stream<String> stream = list.stream();
        //对数组流化
//        String []arr={};
//        Stream<String> stream1 = Arrays.stream(arr);
//        //用stream本身流化工具
//        Stream<String> stringStream = Stream.of("1", "2", "3");


        //2.用中间操作对集合处理（有很多次）
        Stream<String> stream1 = stream.distinct();
        Stream<String> stream2 = stream1.filter(e -> Integer.valueOf(e) > 5);

        //3.用终止操作输出结果（只有一次）
        List<String> collect = stream2.collect(Collectors.toList());
        collect.forEach(System.out::println);
    //最终版
        List<String> collect1 = list.stream().distinct().collect(Collectors.toList());
    }
}
